package com.example.database_manage.administractor;


import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.ImageView;

import com.example.database_manage.R;
import android.widget.ImageButton;
import android.support.v7.widget.Toolbar;

//学生端与管理端的切换
public class Container extends AppCompatActivity {
    private student_Fragment fg_student;
    private Common_Fragment fg_admin;

    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_container);

        final ImageView id1 = findViewById(R.id.xueshengduan);
        final ImageView id2 = findViewById(R.id.guanliyuan);

        id1.setBackgroundColor(R.color.colorfragment);
        id2.setBackgroundColor(R.color.colorfragment);

        fg_student = new student_Fragment();
        fg_admin  = new Common_Fragment();

        getSupportFragmentManager().beginTransaction().add(R.id.framelayout, fg_student).commitAllowingStateLoss();

        View.OnClickListener listener = new View.OnClickListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onClick(View v) {

//                FragmentManager fm = getSupportFragmentManager();
//                FragmentTransaction ft = fm.beginTransaction();
//                Fragment f = null;
                switch (v.getId())
                {
                    case R.id.xueshengduan:
                        getSupportFragmentManager().beginTransaction().replace(R.id.framelayout, fg_student).addToBackStack(null).commitAllowingStateLoss();
                        id1.setBackgroundColor(Color.WHITE);
                        id2.setBackgroundColor(R.color.colorfragment);

                        break;
                    case R.id.guanliyuan:

                        getSupportFragmentManager().beginTransaction().replace(R.id.framelayout, fg_admin).addToBackStack(null).commitAllowingStateLoss();
                        id2.setBackgroundColor(Color.WHITE);
                        id1.setBackgroundColor(R.color.colorfragment);

                    default:

                        break;

                }
            }
        };
        id1.setOnClickListener(listener);
        id2.setOnClickListener(listener);

        }

}
